package de.hska.algo.labor2010.strecken;

import java.util.ArrayList;


/**
 * holds {@link Line} s around a circle as tangents to the circle
 * 
 * @author Daniela Brenner
 * @version 1.0
 */
public class TangentLines implements LinesGenerator {

	private ArrayList<Line> lines;
	private Point origin;

	private double radius;
	
	
	public TangentLines(int n) {
		radius = 100.0;
		origin = new Point(120.0,120.0);
		lines = new ArrayList<Line>(n);
		create(n);
		
	}
	public TangentLines(int n, double r){
		radius = r;
		origin = new Point(r+1,r+1);
		lines = new ArrayList<Line>(n);
		create(n);
	}



	@Override
	public void create(int n) {
		if(n < 3){
			throw new IllegalArgumentException("Provide at least 3 lines, in order to get intersections");
		}
		
		double step = 2*Math.PI / n;
		System.out.println("STEP:  "+ step + "\n##################################################");
		double x1 = radius + origin.getX() , y1= origin.getY();
		double x2= 0, y2=0; 
		//double angle;
		double rad;
		for(int i = 1; i < n; i++){
			//angle =  i * step;
			rad = i*step;
		
//			x2 = Math.cos(degreeToRadiant(angle))  * radius + origin.getX() ;
//			y2 = Math.sin(degreeToRadiant(angle))  * radius + origin.getY();
			x2 = Math.cos(rad)  * radius + origin.getX() ;
			y2 = Math.sin(rad)  * radius + origin.getY();
			lines.add(new Line(x1,y1,x2,y2));
			x1 = x2;
			y1 = y2;
			
		}
		x1 = radius + origin.getX();
		y1 = origin.getY();
		lines.add(new Line(x2,y2,x1,y1));
		

	}
	public ArrayList<Line> getLines() {
		return lines;
	}
	public void setLines(ArrayList<Line> lines) {
		this.lines = lines;
	}
	
	

	@Override
	public String toString() {
		String sth = "Lines\n";
		int i = 0;
		for (Line line : lines) {
			sth+= i + ": " + line.toString();
			i++;
		}
		return sth;

	}

	
	
	private double degreeToRadiant(double deg){
		return (deg * Math.PI) / 180.0;
	}
	

}
